<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
    <title>Login</title>
</h:head>

<h:body onload="#{loginManagedBean.logout()}">
    <p:panel header="Login">
    <h:form id="login">
        <h3><p:outputLabel value="Sezione Utente" rendered="#{!loginManagedBean.isImpiegato and !loginManagedBean.isAdmin or loginManagedBean.fromAmico}"/></h3>
        <h3><p:outputLabel value="Sezione Impiegato" rendered="#{loginManagedBean.isImpiegato and !loginManagedBean.fromAmico}"/></h3>
        <h3><p:outputLabel value="Sezione Admin" rendered="#{loginManagedBean.isAdmin and !loginManagedBean.fromAmico}"/></h3>
        <p:outputLabel value="#{loginManagedBean.errorMessage}"/>
        <h:panelGrid columns="2" cellpadding="5">
            <p:outputLabel value="Email:" rendered="#{!loginManagedBean.isImpiegato and !loginManagedBean.isAdmin or loginManagedBean.fromAmico}"/>
            <p:outputLabel value="Email impiegato:" rendered="#{loginManagedBean.isImpiegato and !loginManagedBean.fromAmico}"/>
            <p:outputLabel value="Email admin:" rendered="#{loginManagedBean.isAdmin and !loginManagedBean.fromAmico}"/>
            <p:inputText id="email" value="#{loginManagedBean.email}"/>
            <p:outputLabel value="Password:"/>
            <p:password id="password" value="#{loginManagedBean.password}"/>
            <p:commandButton id="submit" value="Login" action="#{loginManagedBean.login()}" ajax="false" />
            <p:messages redisplay="false" />
        </h:panelGrid>
    </h:form>
    <h:form>
	    <h:panelGrid columns="1">
	    	<h:link value="Registrati" outcome="registrazione" rendered="#{!loginManagedBean.isImpiegato and !loginManagedBean.isAdmin or loginManagedBean.fromAmico}"/>
	    	<h:link value="Accesso Impiegato" outcome="impiegato/home" rendered="#{!loginManagedBean.isImpiegato and !loginManagedBean.fromAmico}"/>
	    	<h:link value="Accesso Admin" outcome="admin/home" rendered="#{!loginManagedBean.isAdmin and !loginManagedBean.fromAmico}"/>
	    	<h:link value="Torna all'accesso utente" outcome="login" rendered="#{(loginManagedBean.isImpiegato or loginManagedBean.isAdmin) and !loginManagedBean.fromAmico}"/>
	    </h:panelGrid>
    </h:form>
    </p:panel>
    <p:panel header="Ricerca pacchetto per codice" rendered="#{!loginManagedBean.fromAmico}">
    	<h:form id="ricercaIDForm">
    		<p:outputLabel value="Identificativo pacchetto: "/> <p:inputText value = "#{amicoManagedBean.idPacchetto}"/> <p:commandButton value = "Carica pacchetto" action = "#{amicoManagedBean.caricaPacchetto()}"/>
    		<p:messages autoUpdate="true" closable="true" id="notFoundError" redisplay="false"/>
    	</h:form>
    </p:panel>
</h:body>
</html>
